﻿using NewChillers.Utils;

using Sys;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewChillers.Helpers
{
    public class IOHelper
    {
        private static void IO_Write(string taskName, string address, byte[] arr)
        {
            IntPtr taskHandleOpen = (IntPtr)(0);
            IntPtr taskglobeValve2Turnoff = (IntPtr)(0);
            ArtDAQ.ArtDAQ_StopTask(taskHandleOpen);
            ArtDAQ.ArtDAQ_ClearTask(taskHandleOpen);
            Int32 TurnoffError = ArtDAQ.ArtDAQ_CreateTask(taskName, out taskglobeValve2Turnoff);
            TurnoffError = ArtDAQ.ArtDAQ_CreateDOChan(taskglobeValve2Turnoff, address, "", ArtDAQ.ArtDAQ_Val_ChanForAllLines);
            TurnoffError = ArtDAQ.ArtDAQ_StartTask(taskglobeValve2Turnoff);
            TurnoffError = ArtDAQ.ArtDAQ_WriteDigitalLines(taskglobeValve2Turnoff, 1, 1, 10.0, ArtDAQ.ArtDAQ_Val_GroupByChannel, arr, out IO_Address.read_N, (IntPtr)0);
            ArtDAQ.ArtDAQ_StopTask(taskglobeValve2Turnoff);
            ArtDAQ.ArtDAQ_ClearTask(taskglobeValve2Turnoff);
        }

        private static void IO_Read(string taskName, string address, byte[] arr)
        { 
        }

        #region 警报器
        // 红灯
        public static void RedLight_Open()
        {
            IO_Write("redlightopen", IO_Address.strLineName_RedLight, IO_Address.dataOn);
        }
        public static void RedLight_Close()
        {
            IO_Write("redlightclose", IO_Address.strLineName_RedLight, IO_Address.dataClose);
        }
        // 黄灯
        public static void YellowLight_Open()
        {
            IO_Write("yellowlightopen", IO_Address.strLineName_YellowLight, IO_Address.dataOn);
        }
        public static void YellowLight_Close()
        {
            IO_Write("yellowlightclose", IO_Address.strLineName_YellowLight, IO_Address.dataClose);
        }
        // 绿灯
        public static void GreenLight_Open()
        {
            IO_Write("greenlightopen", IO_Address.strLineName_GreenLight, IO_Address.dataOn);
        }
        public static void GreenLight_Close()
        {
            IO_Write("greenlightclose", IO_Address.strLineName_GreenLight, IO_Address.dataClose);
        }
        // 蜂鸣器
        public static void Buzz_Open()
        {
            IO_Write("buzztopen", IO_Address.strLineName_Buzz, IO_Address.dataOn);
        }
        public static void Buzz_Close()
        {
            IO_Write("buzzclose", IO_Address.strLineName_Buzz, IO_Address.dataClose);
        }
        //蜂鸣器提示---响3次
        public static async void TipBuzz()
        {
            for (int i = 0; i < 3; i++)
            {
                Buzz_Open();
                await Task.Delay(300);
                Buzz_Close();
                await Task.Delay(300);
            }

        }

        #endregion

        #region 泵
        // 机械泵
        public static void MechanicalPump_Open()
        {
            IO_Write("pumptopen", IO_Address.strLineName_mechanicalPump, IO_Address.dataOn);
        }
        public static void MechanicalPump_Close()
        {
            IO_Write("pumptclose", IO_Address.strLineName_mechanicalPump, IO_Address.dataClose);
        }
        //分子泵
        public static void MolecularPump_Open()
        {
            IO_Write("pumptopen", IO_Address.strLineName_molecularPump, IO_Address.dataOn);
        }
        public static void MolecularPump_Close()
        {
            IO_Write("pumptclose", IO_Address.strLineName_molecularPump, IO_Address.dataClose);
        }
        #endregion
    }
}
